package cn.codeartist.springboot.component.http.proxy.impl;


import cn.codeartist.springboot.component.http.proxy.HttpProxy;
import cn.codeartist.springboot.component.http.proxy.HttpProxyEntity;

import java.util.Map;

/**
 * HttpProxy配置项构建器
 *
 * @author 艾江南
 * @date 2019/3/24
 */
public class HttpProxyBuilder extends HttpProxyEntity {

    public HttpProxyBuilder host(String host) {
        this.host = host;
        return this;
    }

    public HttpProxyBuilder header(Map<String, String> header) {
        this.header = header;
        return this;
    }

    public HttpProxyBuilder readTimeout(Integer readTimeout) {
        this.readTimeout = readTimeout;
        return this;
    }

    public HttpProxyBuilder connectTimeout(Integer connectTimeout) {
        this.connectTimeout = connectTimeout;
        return this;
    }

    public HttpProxy build() {
        DefaultHttpProxy proxy = new DefaultHttpProxy();
        setProperties(proxy);
        return proxy;
    }

    public HttpProxy sentinel() {
        SentinelHttpProxy proxy = new SentinelHttpProxy();
        setProperties(proxy);
        return proxy;
    }

    private void setProperties(HttpProxyEntity proxy) {
        proxy.setHost(host);
        proxy.setHeader(header);
        proxy.setReadTimeout(readTimeout);
        proxy.setConnectTimeout(connectTimeout);
    }
}
